package game.scene.sceneobject;

import common.Coordinate;
import common.Rectangle;

import engine.video.blit.BlitMode_E;
import engine.video.blit.Blitter;
import engine.video.blit.PixelBuffer_I;

public class Rectangle_SO extends SceneObject_A {
	public Rectangle Boundry;
	public Coordinate Location;
	public byte Color;
	public BlitMode_E Mode;
	
	public Rectangle_SO() {
		Color = (byte)0xFF;
		Mode = BlitMode_E.COPY;
		Boundry = new Rectangle();
		Location = new Coordinate();
	}
	
	public Rectangle_SO(Rectangle rectangle) {
		Color = (byte)0xFF;
		Mode = BlitMode_E.COPY;
		Boundry = new Rectangle();
		Location = new Coordinate();
		rectangle.copyTo(Boundry);
		updateVisRect();
	}

	
	public void setLocation(Coordinate location) {
		if(location == null) {
			return;
		}
		Location = new Coordinate(location.X, location.Y);
		updateVisRect();
	}
	
	public void setBoundry(Rectangle boundry) {
		if(boundry == null) {
			return;
		}
		boundry.copyTo(Boundry);
		updateVisRect();
	}
	
	private void updateVisRect() {
		Boundry.copyTo(VisRect);
		VisRect.X += Location.X;
		VisRect.Y += Location.Y;
	}
	// SceneObject_A -----------------------------------------------------------
	
	@Override
	public boolean isOverlapping(Rectangle queryRect) {
		return this.VisRect.overlaps(queryRect);
	}
	
	
	@Override
	public void render(Coordinate camera, Blitter blitter) {
		Rectangle rect = new Rectangle();
		this.VisRect.copyTo(rect);
		rect.X -= camera.X;
		rect.Y -= camera.Y;
		blitter.blitRectangle(Color, rect, blitter.TargetBuffer, Mode);
	}

}
